package org.jetlinks.pro.openapi.manager;

import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.basic.web.GeneratedToken;
import org.hswebframework.web.authorization.basic.web.ReactiveUserTokenGenerator;
import org.hswebframework.web.authorization.simple.DefaultAuthorizationAutoConfiguration;
import org.hswebframework.web.authorization.token.DefaultUserTokenManager;
import org.hswebframework.web.authorization.token.UserTokenManager;
import org.hswebframework.web.starter.jackson.CustomCodecsAutoConfiguration;
import org.hswebframework.web.system.authorization.defaults.configuration.AuthorizationServiceAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;
import java.util.Map;

@Configuration
@ImportAutoConfiguration({
    DefaultAuthorizationAutoConfiguration.class,
    AuthorizationServiceAutoConfiguration.class,
    CodecsAutoConfiguration.class,
    JacksonAutoConfiguration.class,
    CustomCodecsAutoConfiguration.class
})
public class OpenApiTestConfiguration {


    @Bean
    public UserTokenManager userTokenManager(){
        return new DefaultUserTokenManager();
    }


    @Bean
    public ReactiveUserTokenGenerator testTokenGenerator(){
        return new ReactiveUserTokenGenerator() {
            @Override
            public String getTokenType() {
                return "_test";
            }

            @Override
            public GeneratedToken generate(Authentication authentication) {
                return new GeneratedToken() {
                    @Override
                    public Map<String, Object> getResponse() {
                        return Collections.emptyMap();
                    }

                    @Override
                    public String getToken() {
                        return "test";
                    }

                    @Override
                    public String getType() {
                        return getTokenType();
                    }

                    @Override
                    public long getTimeout() {
                        return 100000;
                    }
                };
            }
        };
    }
}
